﻿using Keyer.DataBase.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;

namespace Keyer.DataBase.Mapping.LocalDB
{
    public class ModuleAppMap : EntityTypeConfiguration<sys_moduleapp>  
    {
       public ModuleAppMap()
        {
            // 表名
            this.ToTable("ModuleApp");

            // 主键
            this.HasKey(t => t.id);
            this.Property(t => t.id)
                .HasColumnName("id").HasMaxLength(40);

            // 属性设置
            this.Property(t => t.moduleId)
                .HasColumnName("moduleId")
                .HasMaxLength(40);
            this.Property(t => t.appId)
                .HasColumnName("appId")
                .HasMaxLength(40);

            // 关联设置
            this.HasRequired(t => t.module)
                .WithMany(t => t.moduleApps)
                .HasForeignKey(t => t.moduleId)
                .WillCascadeOnDelete(false);

            this.HasRequired(t => t.app)
                 .WithMany(t => t.moduleApps)
                 .HasForeignKey(t => t.appId)
                 .WillCascadeOnDelete(false);
        }
    }
}
